package com.ruoyi.web.controller.situation;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.situation.domain.Situation;
import com.ruoyi.situation.service.ISituationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 态势估值Controller
 * 
 * @author ruoyi
 * @date 2024-11-15
 */
@RestController
@RequestMapping("/situ/situation")
public class SituationController extends BaseController
{
    @Autowired
    private ISituationService situationService;

    /**
     * 查询态势估值列表
     */
    @PreAuthorize("@ss.hasPermi('control:situation:list')")
    @GetMapping("/list")
    public TableDataInfo list(Situation situation)
    {
        startPage();
        List<Situation> list = situationService.selectSituationList(situation);
        return getDataTable(list);
    }

    /**
     * 导出态势估值列表
     */
    @PreAuthorize("@ss.hasPermi('control:situation:export')")
    @Log(title = "态势估值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Situation situation)
    {
        List<Situation> list = situationService.selectSituationList(situation);
        ExcelUtil<Situation> util = new ExcelUtil<Situation>(Situation.class);
        util.exportExcel(response, list, "态势估值数据");
    }

    /**
     * 获取态势估值详细信息
     */
    @PreAuthorize("@ss.hasPermi('control:situation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(situationService.selectSituationById(id));
    }

    /**
     * 新增态势估值
     */
    @PreAuthorize("@ss.hasPermi('control:situation:add')")
    @Log(title = "态势估值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Situation situation)
    {
        return toAjax(situationService.insertSituation(situation));
    }

    /**
     * 修改态势估值
     */
    @PreAuthorize("@ss.hasPermi('control:situation:edit')")
    @Log(title = "态势估值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Situation situation)
    {
        return toAjax(situationService.updateSituation(situation));
    }

    /**
     * 删除态势估值
     */
    @PreAuthorize("@ss.hasPermi('control:situation:remove')")
    @Log(title = "态势估值", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(situationService.deleteSituationByIds(ids));
    }


    /**
     * 安全态势得分
     */
    @GetMapping("/getScoreList")
    public List getScoreList() {
        List<String> list = situationService.getScoreList();
        return list;
    }


    /**
     * 生产态势得分
     */
    @GetMapping("/getProductScoreList")
    public List getProductScoreList() {
        List<String> list = situationService.getProductScoreList();
        return list;
    }

    /**
     * 读取安全态势得分缓存分值
     */
    @GetMapping("/getCacheScoreList")
    public List getCacheScoreList() {
        List<String> list = situationService.getCacheScoreList();
        return list;
    }

    /**
     * 读取缓存  1天设备故障次数
     */
    @GetMapping("/getCacheDeviceFaultList")
    public List getCacheDeviceFaultList() {
        List<String> list = situationService.getCacheDeviceFaultList();
        return list;
    }

    /**
     * 7天设备故障率
     */
    @GetMapping("/getDeviceFaultList/{type}")
    public AjaxResult getDeviceFaultList(@PathVariable String type) {
        List<Object> list = situationService.getDeviceFaultList(type);
//        System.out.println(type);
//        System.out.println(list);

        return success(list);
    }


    /**
     * 7天设备功耗
     */
    @GetMapping("/getDevicePowerList/{type}/{num}")
    public AjaxResult getDevicePowerList(@PathVariable String type,@PathVariable String num) {
        List<Object> list = situationService.getDevicePowerList(type,num);
//        System.out.println(type);
//        System.out.println(num);
//        System.out.println(list);

        return success(list);
    }

}

